//
//  PersonHeadUserView.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/3/17.
//  Copyright © 2016年 game. All rights reserved.
//

#import "PersonHeadUserView.h"
#import "UIImageView+WebCache.h"
#define imageHight (SCREEN_HEIGHT*0.2-60)

@interface PersonHeadUserView ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jianytouwidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jiantouHight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *gradHight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *linWidth;
@property (nonatomic,strong) AppDelegate *app;

//@property (nonatomic,strong) UserDataModel *model;

@end

@implementation PersonHeadUserView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        
        
    }
    return self;
}

-(void)awakeFromNib{
    
    self.backgroundColor = [UIColor clearColor];

    self.headImage.image = [UIImage imageNamed:@"the_default_avatar"];
    
    self.jiantouHight.constant = 30;
    
    self.jianytouwidth.constant = 15;
    
    self.headWidth.constant = imageHight;
    
    self.headHight.constant = imageHight;
    
    radius(self.headImage, imageHight/2);
    
    self.linWidth.constant = 0.5;
    
    self.topLogin.alpha = 0;
    self.name.alpha = 0;
    self.grad.alpha = 0;
    self.weiwang.alpha = 0;
    self.yufeng.alpha = 0;
    self.lin.alpha = 0;
}

-(void)setModel:(UserDataModel *)model{
    _model = model;

    self.app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    if ([self.app.isLogin isEqualToString:@"YES"]) {
        
        self.topLogin.alpha = 1;
        
        if (_model!=nil) {
            self.topLogin.alpha = 0;
            self.name.alpha = 1;
            self.grad.alpha = 1;
            self.weiwang.alpha = 1;
            self.yufeng.alpha = 1;
            self.lin.alpha = 1;
            
            NSURL *url = [NSURL URLWithString:_model.avatar];
            
            [self.headImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"the_default_avatar"] options:SDWebImageCacheMemoryOnly];
            
            self.name.text = _model.username;
            self.weiwang.text = [NSString stringWithFormat:@"金钱：%@",_model.money];
            self.yufeng.text = [NSString stringWithFormat:@"积分：%@",_model.credit];
            
            self.grad.text = [NSString stringWithFormat:@"Lv.%@",_model.user_level];
        }else{
        
        }
        
    }else{
        
        [self.headImage sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"the_default_avatar"] options:SDWebImageCacheMemoryOnly];
        
        self.topLogin.alpha = 1;
        self.name.alpha = 0;
        self.grad.alpha = 0;
        self.weiwang.alpha = 0;
        self.yufeng.alpha = 0;
        self.lin.alpha = 0;
    }
}
@end